package com.javaclimb.music.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javaclimb.music.dao.RankMapper;
import com.javaclimb.music.domain.Rank;
import com.javaclimb.music.service.RankService;
import org.springframework.stereotype.Service;

@Service
public class RankServiceImpl extends ServiceImpl<RankMapper, Rank> implements RankService {

    /**
     * 查总评分人数
     *
     * @param songListId
     */
    @Override
    public int selectRankNum(Integer songListId) {
        return this.getBaseMapper().selectRankNum(songListId);
    }

    /**
     * 计算平均分
     *
     * @param songListId
     */
    @Override
    public int rankOfSongListId(Integer songListId) {
        int rankNum = this.selectRankNum(songListId);
        if (rankNum == 0) {
            return 5;
        }
        return this.getBaseMapper().selectScoreSum(songListId) / rankNum;
    }
}
